/*
 * odometer.c
 *
 *  Created on: 12.05.2011
 *      Author: Axel, Thomas
 */

#include <avr/io.h>

#include "odometer.h"

#define IPR 16.0	/*signals per revolution*/

uint8_t nReadOld = 0x00; /*previous reading*/

bool bGetRevolution(fixedpoint_t *pwRevolutionLeft,
		fixedpoint_t *pwRevolutionRight) {
	uint8_t nResultSignals;
	uint8_t nRead = PINA; /*read pin register*/
	nRead &= ((1 << PINA6) | (1 << PINA7)); /*delete not used pins*/
	nResultSignals = nRead ^ nReadOld; /*check signal change*/
	/*when signal change add part off the revolution*/
	if (nResultSignals & (1 << PINA6)) {
		*pwRevolutionLeft += fixedpoint_fromFloat(1.0 / IPR);
	}
	if (nResultSignals & (1 << PINA7)) {
		*pwRevolutionRight += fixedpoint_fromFloat(1.0 / IPR);
	}
	nReadOld = nRead; /*save read pin register*/

	return true;
}
